/**
 * 懒加载指令
 * @param el
 * @param binding
 */
const lazyLoadDirective = {
  mounted(el: HTMLElement, binding) {
    const observer = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          const content = binding.value;
          el.innerHTML = content;
          observer.unobserve(el);
        }
      });
    });

    observer.observe(el);
  }
};

export default lazyLoadDirective;